package com.chezai.client.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.widget.EditText;

import com.chezai.client.R;

import butterknife.BindView;

/**
 * 小鹿读卡器 弹窗
 * Created by likunyang on 2017/8/5.
 */

public class ReadCardDialog extends BaseDialog implements TextWatcher {

    @BindView(R.id.edCard)
    EditText edCard;
    private OnInputOverListener listener;

    public ReadCardDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getDialogLayoutResId() {
        return R.layout.dailog_read_card;
    }
    @Override
    protected void initView(Context context) {
    }

    @Override
    protected float getwScale() {
        return 0.88f;
    }

    @Override
    protected float gethScale() {
        return 0.8f;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected void setListener() {
        edCard.addTextChangedListener(this);
    }

    public void setOnInputOverListener(OnInputOverListener listener) {
        this.listener = listener;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        String cardNumBer = s.toString().trim();
        if (cardNumBer.length() >= 10) {
            if (listener != null) {
                listener.onInputOver(this, cardNumBer);
            }
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    public interface OnInputOverListener {
        void onInputOver(Dialog dialog, String result);
    }
}
